package com.example.runningman.run;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;

import com.example.runningman.MainActivity;
import com.example.runningman.R;
import com.example.runningman.adapter.Art_adapter;
import com.example.runningman.adapter.Run_adapter;
import com.example.runningman.bean.BaiduPoints;
import com.example.runningman.dao.PointsDao;
import com.example.runningman.database.BaiduPointsDatebase;

import java.util.List;

public class CountryActivity extends AppCompatActivity {
    BaiduPointsDatebase baiduPointsDatebase ;
    PointsDao pointsDao;
    RecyclerView mRecyclerView;
    ImageButton imageButton;
    Run_adapter run_adapter;
    LinearLayoutManager layoutManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_country);

        baiduPointsDatebase= BaiduPointsDatebase.getInstance(CountryActivity.this);
        pointsDao=baiduPointsDatebase.getPointsDao();
        List<BaiduPoints> list =pointsDao.selectAllBaiduPoints();
        imageButton = findViewById(R.id.back3);

        mRecyclerView = findViewById(R.id.paobu);
        run_adapter = new Run_adapter(list, CountryActivity.this);
        layoutManager = new LinearLayoutManager(CountryActivity.this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setAdapter(run_adapter);
        run_adapter.setOnItemClickListener(new Run_adapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                Intent intent = new Intent(CountryActivity.this,StaticDemo.class);
                Bundle bundle=new Bundle();
                bundle.putInt("count",position);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(CountryActivity.this, MainActivity.class);
                startActivity(intent);
            }
        });
        for (BaiduPoints points:list
        ) {
            Log.e("ssssss", points.toString());
        }
    }
}
